package com.omkarpatil.learningjpa2.mapping.basic.secondarytable.embedded;

import java.io.Serializable;

import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.AttributeOverride;

@Entity(name="SecondaryTableEmbeddedEmployee")
@Table(name="basic_sec_tab_emb_emp")
@SecondaryTable(name="basic_sec_tab_emb_emp_addr", 
            pkJoinColumns=@PrimaryKeyJoinColumn(name="emp_id"))
public class Employee implements Serializable {
	private int id;
	private String name;
	private Address address;
	
	public Employee() {}

	public Employee(String name, Address adress) {
		this.name = name;
		this.address = adress;
	}

	@Id @GeneratedValue
	public int getId() {
		return id;
	}

	private void setId(int id) {
		this.id = id;
	}

	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Embedded
	@AttributeOverrides({
		@AttributeOverride(name="street", column=@Column(table="basic_sec_tab_emb_emp_addr")),
		@AttributeOverride(name="city", column=@Column(table="basic_sec_tab_emb_emp_addr")),
		@AttributeOverride(name="state", column=@Column(table="basic_sec_tab_emb_emp_addr")),
		@AttributeOverride(name="zipCode", column=@Column(name="ZIP", table="basic_sec_tab_emb_emp_addr"))
	})
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}	
}
